package com.hhhn.wk.main.tab2.view.xiangqing.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
import com.gxz.PagerSlidingTabStrip;
import com.hhhn.wk.R;
import com.hhhn.wk.base.BaseActivity;
import com.hhhn.wk.main.tab2.view.xiangqing.adapter.ItemTitlePagerAdapter;
import com.hhhn.wk.main.tab2.view.xiangqing.fragment.GoodsCommentFragment;
import com.hhhn.wk.main.tab2.view.xiangqing.fragment.GoodsDetailFragment;
import com.hhhn.wk.main.tab2.view.xiangqing.fragment.GoodsInfoFragment;
import com.hhhn.wk.main.tab2.view.xiangqing.widget.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

/**
 * * * * * * * * * * * *
 *
 * @author：文珂 ｡◕‿◕｡ *
 * Data：2018/1/9 0009    ｡◕‿◕｡ *
 * Function：      ｡◕‿◕｡ *
 * 商品详情
 * * * * * * * * * * *
 */
public class CommodityXQActivity extends BaseActivity {
    public PagerSlidingTabStrip psts_tabs;
    public NoScrollViewPager vp_content;
    public TextView tv_title;

    private List<Fragment> fragmentList = new ArrayList<>();
    private GoodsInfoFragment goodsInfoFragment;
    private GoodsDetailFragment goodsDetailFragment;
    private GoodsCommentFragment goodsCommentFragment;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;


    @Override
    protected void setOnCreateContentView() {
        setContentView(R.layout.commodityxiang);
    }

    @Override
    protected void initView() {
        psts_tabs = (PagerSlidingTabStrip) findViewById(R.id.psts_tabs);
        vp_content = (NoScrollViewPager) findViewById(R.id.vp_content);
        tv_title = (TextView) findViewById(R.id.tv_title);
    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        String goods_id = intent.getStringExtra("goods_id");
        goodsInfoFragment = new GoodsInfoFragment();
        Bundle bundle = new Bundle();
        bundle.putString("goods_id", goods_id);
        goodsInfoFragment.setArguments(bundle);
        fragmentList.add(goodsInfoFragment);

        goodsDetailFragment = new GoodsDetailFragment();
        Bundle bundlegoodsDetai = new Bundle();
        bundlegoodsDetai.putString("goods_id", goods_id);
        goodsDetailFragment.setArguments(bundle);
        fragmentList.add(goodsDetailFragment);


        goodsCommentFragment = new GoodsCommentFragment();
        Bundle bundlegood = new Bundle();
        bundlegood.putString("goods_id", goods_id);
        goodsCommentFragment.setArguments(bundle);
        fragmentList.add(goodsCommentFragment);

//        fragmentList.add(goodsDetailFragment = new GoodsDetailFragment());
//        fragmentList.add(goodsCommentFragment = new GoodsCommentFragment());
        vp_content.setAdapter(new ItemTitlePagerAdapter(getSupportFragmentManager(),
                fragmentList, new String[]{"商品", "详情", "评价"}));
//        vp_content.setAdapter(new ItemTitlePagerAdapter(getSupportFragmentManager(),
//                fragmentList, new String[]{"商品", "详情"}));
        vp_content.setOffscreenPageLimit(3);
        psts_tabs.setViewPager(vp_content);
    }

    @Override
    protected void initClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    public Action getIndexApiAction() {
        Thing object = new Thing.Builder()
                .setName("CommodityXQ Page") // TODO: Define a title for the content shown.
                // TODO: Make sure this auto-generated URL is correct.
                .setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
                .build();
        return new Action.Builder(Action.TYPE_VIEW)
                .setObject(object)
                .setActionStatus(Action.STATUS_TYPE_COMPLETED)
                .build();
    }

    @Override
    public void onStart() {
        super.onStart();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client.connect();
        AppIndex.AppIndexApi.start(client, getIndexApiAction());
    }

    @Override
    public void onStop() {
        super.onStop();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        AppIndex.AppIndexApi.end(client, getIndexApiAction());
        client.disconnect();
    }
}
